package com.wiser.beseelcurveanim.sbessel;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;

/**
 * @author Wiser
 * 
 *         结束位置控件
 */
public class EndImageView extends AppCompatImageView {

	private Paint	paint	= new Paint(Paint.ANTI_ALIAS_FLAG);

	private int		radius	= 30;

	public EndImageView(Context context, AttributeSet attrs) {
		super(context, attrs);

		paint.setColor(Color.BLUE);
	}

	@Override protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		canvas.drawRect(0, 0, 2 * radius, 2 * radius, paint);
	}

	@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		int widthMode = MeasureSpec.getMode(widthMeasureSpec);
		int heightMode = MeasureSpec.getMode(heightMeasureSpec);
		int widthSize = MeasureSpec.getSize(widthMeasureSpec);
		int heightSize = MeasureSpec.getSize(heightMeasureSpec);

		int width = 0;
		int height = 0;

		switch (widthMode) {
			case MeasureSpec.EXACTLY:
			case MeasureSpec.AT_MOST:
				width = 2 * radius;
				break;
			case MeasureSpec.UNSPECIFIED:
				width = widthSize;
				break;
		}

		switch (heightMode) {
			case MeasureSpec.EXACTLY:
			case MeasureSpec.AT_MOST:
				height = 2 * radius;
				break;
			case MeasureSpec.UNSPECIFIED:
				height = heightSize;
				break;
		}
		setMeasuredDimension(width, height);
	}
}
